<?php
namespace App\Module\Admin\Controller;

use App\Common\Controller\AbstractController;
use App\Module\Admin\Request\Works\CreateRequest;
use App\Module\Admin\Request\Works\UpdateRequest;
use App\Module\Admin\Service\WorksService;
use Hyperf\Di\Annotation\Inject;

class WorksController extends AbstractController{

    /**
     * @Inject()
     * @var WorksService $worksService
     */
    private $worksService;

    public function search(){
        $child_name = $this->request->input("child_name");
        $pagesize = $this->request->input("pagesize");

        return $this->response->json($this->worksService->search($child_name,$pagesize));
    }

    public function add(CreateRequest $request){
        return $this->response->json($this->worksService->create($request));
    }

    public function getById(int $id){
        return $this->response->json($this->worksService->getById($id));
    }

    public function edit(UpdateRequest $request,int $id){
        return $this->response->json($this->worksService->update($request,$id));
    }

    public function delete(int $id){
        return $this->response->json($this->worksService->delete($id));
    }
}